import { createRouter, createWebHistory } from 'vue-router'
import useBaseStore from '@/stores/baseStore.ts'

const router = createRouter({
	history: createWebHistory(),
	routes: [
		{
			path: '',
			redirect: '/home'
		},
		{
			path: '/',
			redirect: '/home'
		},
		{
			path: '/home',
			name: 'home',
			component: () => import('@/views/page/HomeVue.vue'),
			meta: {
				title: '工作台',
			}
		},
		{
			path: '/author',
			name: 'author',
			component: () => import('@/views/page/AuthorVue.vue'),
			meta: {
				title: '作者管理',
			}
		},
		{
			path: '/cartoon',
			name: 'cartoon',
			component: () => import('@/views/page/CartoonVue.vue'),
			meta: {
				title: '漫画信息管理',
			}
		},
		{
			path: '/cartoonType',
			name: 'cartoonType',
			component: () => import('@/views/page/CartoonTypeVue.vue'),
			meta: {
				title: '漫画类型管理',
			}
		},
		{
			path: '/relationCartoonType',
			name: 'relationCartoonType',
			component: () => import('@/views/page/RelationCartoonTypeVue.vue'),
			meta: {
				title: '对应关系管理(漫画-类型)',
			}
		},
		{
			path: '/relationCartoonAuthor',
			name: 'relationCartoonAuthor',
			component: () => import('@/views/page/RelationCartoonAuthorVue.vue'),
			meta: {
				title: '对应关系管理(漫画-作者)',
			}
		},
		{
			path: '/novel',
			name: 'novel',
			component: () => import('@/views/page/NovelVue.vue'),
			meta: {
				title: '电子书信息管理',
			}
		},
		{
			path: '/novelType',
			name: 'novelType',
			component: () => import('@/views/page/NovelTypeVue.vue'),
			meta: {
				title: '电子书类型管理',
			}
		},
		{
			path: '/relationNovelType',
			name: 'relationNovelType',
			component: () => import('@/views/page/RelationNovelTypeVue.vue'),
			meta: {
				title: '对应关系管理(电子书-类型)',
			}
		},
		{
			path: '/relationNovelAuthor',
			name: 'relationNovelAuthor',
			component: () => import('@/views/page/RelationNovelAuthorVue.vue'),
			meta: {
				title: '对应关系管理(电子书-作者)',
			}
		},
		{
			path: '/admin',
			name: 'admin',
			component: () => import('@/views/page/AdminVue.vue'),
			meta: {
				title: '管理员列表',
			}
		},
		{
			path: '/file',
			name: 'file',
			component: () => import('@/views/page/FileVue.vue'),
			meta: {
				title: '文件管理',
			}
		},
	]
})

// 非必要代码，暂时注释掉
// router.beforeEach((to, from) => {
// 	const baseStore = useBaseStore();
// 	if (!baseStore.isLogin) {
// 		return false;
// 	}
// 	return true;
// })

router.afterEach((to, from) => {

	const baseStore = useBaseStore();
	if ('/' + baseStore.getRoute !== to.path) {
		baseStore.route = to.path.replace('/', '')
		console.log(baseStore.getRoute);
	}

})

export default router
